<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<div class="grid">
    <?php $randomId = rand(); ?>
    <div class="admin__table-wrapper">
        <table class="data-grid">
            <thead>
                <tr>
                    <th class="data-grid-checkbox-cell">
                        <label class="data-grid-checkbox-cell-inner">
                            <input type="checkbox"
                                   id="select-items-<?php /* @noEscape */ echo $randomId; ?>"
                                   onchange="packaging.checkAllItems(this);"
                                   class="checkbox admin__control-checkbox"
                                   title="<?php /* @escapeNotVerified */ echo __('Select All') ?>">
                            <label for="select-items-<?php /* @noEscape */ echo $randomId; ?>"></label>
                        </label>
                    </th>
                    <th class="data-grid-th"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
                    <th class="data-grid-th"><?php /* @escapeNotVerified */ echo __('Weight') ?></th>
                    <th class="data-grid-th" <?php echo $block->displayCustomsValue() ? '' : 'style="display: none;"' ?>>
                        <?php /* @escapeNotVerified */ echo __('Customs Value') ?>
                    </th>
                    <th class="data-grid-th"><?php /* @escapeNotVerified */ echo __('Qty Ordered') ?></th>
                    <th class="data-grid-th"><?php /* @escapeNotVerified */ echo __('Qty') ?></th>
                </tr>
            </thead>
            <tbody>
            <?php $i=0; ?>
            <?php foreach ($block->getCollection() as $item): ?>
                <?php
                    $_order = $block->getShipment()->getOrder();
                    $_orderItem = $_order->getItemById($item->getOrderItemId());
                ?>
                <?php if ($item->getIsVirtual()
                    || ($_orderItem->isShipSeparately() && !($_orderItem->getParentItemId() || $_orderItem->getParentItem()))
                    || (!$_orderItem->isShipSeparately() && ($_orderItem->getParentItemId() || $_orderItem->getParentItem()))): ?>
                    <?php continue; ?>
                <?php endif; ?>
                <tr class="data-grid-controls-row data-row <?php echo ($i++ % 2 != 0) ? '_odd-row' : ''; ?>">
                    <td class="data-grid-checkbox-cell">
                        <?php $id = $item->getId() ? $item->getId() : $item->getOrderItemId(); ?>
                        <label class="data-grid-checkbox-cell-inner">
                            <input type="checkbox"
                                   name=""
                                   id="select-item-<?php /* @noEscape */ echo $randomId . '-' . $id; ?>"
                                   value="<?php /* @escapeNotVerified */ echo $id; ?>"
                                   class="checkbox admin__control-checkbox">
                            <label for="select-item-<?php /* @noEscape */ echo $randomId . '-' . $id; ?>"></label>
                        </label>
                    </td>
                    <td>
                        <?php /* @escapeNotVerified */ echo $item->getName(); ?>
                    </td>
                    <td data-role="item-weight">
                        <?php /* @escapeNotVerified */ echo $item->getWeight(); ?>
                    </td>
                    <?php
                    if ($block->displayCustomsValue()) {
                        $customsValueDisplay = '';
                        $customsValueValidation = ' validate-zero-or-greater ';
                    } else {
                        $customsValueDisplay = ' style="display: none;" ';
                        $customsValueValidation = '';
                    }

                    ?>
                    <td <?php /* @escapeNotVerified */ echo $customsValueDisplay ?>>
                        <input type="text"
                               name="customs_value"
                               class="input-text admin__control-text <?php /* @escapeNotVerified */ echo $customsValueValidation ?>"
                               value="<?php /* @escapeNotVerified */ echo $block->formatPrice($item->getPrice()); ?>"
                               size="10"
                               onblur="packaging.recalcContainerWeightAndCustomsValue(this);">
                    </td>
                    <td>
                        <?php /* @escapeNotVerified */ echo $item->getOrderItem()->getQtyOrdered()*1; ?>
                    </td>
                    <td>
                        <input type="hidden" name="price" value="<?php /* @escapeNotVerified */ echo $item->getPrice(); ?>">
                        <input type="text"
                               name="qty"
                               value="<?php /* @escapeNotVerified */ echo $item->getQty()*1; ?>"
                               class="input-text admin__control-text qty<?php if ($item->getOrderItem()->getIsQtyDecimal()): ?> qty-decimal<?php endif ?>">&nbsp;
                        <button type="button" class="action-delete" data-action="package-delete-item" onclick="packaging.deleteItem(this);" style="display:none;">
                            <span><?php /* @escapeNotVerified */ echo __('Delete') ?></span>
                        </button>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
